package com.shujia.akka.sampleActor

import akka.actor.{Actor, ActorRef, ActorSystem, Props}

object SayHelloActor extends App {
  //  def main(args: Array[String]): Unit = {
  //    println("message ")
  //  }
  //  println("message")

  private val sayHelloSystem: ActorSystem = ActorSystem("SayHelloSystem")

  // ActorRef 可以用于发送消息的对象
  private val sayHelloActor: ActorRef = sayHelloSystem.actorOf(Props[SayHelloActor], "sayHelloActor")

  // 简写
  sayHelloActor ! "hello"
  //  sayHelloActor.!("hello")
}


class SayHelloActor extends Actor {
  override def receive: Receive = {
    // case 表示模式匹配
    case "hello" => {
      println("接受到hello，回应萨瓦迪卡..")
      self ! "OK"
    }
    case "OK" => println("接受到OK 摇摇头..")
    case _ => println("不知道您在说什么..")
  }
}